package com.al.filter;

/**
 * Filter 过滤器
 * */

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.FilterConfig;

//@WebFilter(value = "/*")
//@WebFilter("/*")
@WebFilter(urlPatterns = "/*")
public class AnythingFilter implements Filter {
	private FilterConfig config;
	
	public void init(FilterConfig config) throws javax.servlet.ServletException{
		System.out.println("【 " +config.getFilterName()  + " 】初始化("+ this +")");
		this.config = config;
	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
			throws IOException, ServletException {
		System.out.println("【 " + config.getFilterName() +" 】正在执行过滤("+ this +")");
		chain.doFilter(req, resp); //将 请求 和 响应 向后传递
		
	}
	
	 public void destroy() {
		 System.out.println("【 " + config.getFilterName() +" 】销毁("+ this +")");
	 }

}
